let util = {
    uploadFile: (file) => {
        let formData = new FormData();
        //这里的key(uri和type和name)不能改变,
        formData.append("files", file);   //这里的files就是后台需要的key
        let param = {};
        let params = [];
        params.push("shishidata_every_2mins.findByDateAnddssslh");
        params.push(formData);
        param.params = params;
        param.method = "SmartReportService.query";
        console.log('fromdata------', formData);
        fetch('http://192.168.95.174:3000/remoteCall', {
            method: 'POST',
            headers: {
                'Accept': 'application/json',
                "Content-Type": 'multipart/form-data', // 'Content-Type': 'application/json'
            },
            body: JSON.stringify(param),
        })
            .then((response) => response.json())
            .then((responseData) => {
                console.log('responseData', responseData);
            })
            .catch((error) => { console.log('error', error) });
    },
    /**
    * http post 请求简单封装
    * @param url 请求的URL
    * @param data post的数据
    * @param successCallback 请求成功回调
    * @param failCallback failCallback 请求失败回调
    */
    post: (url, data, successCallback, failCallback) => {

        let formData = new FormData();
        Object.keys(data).map(function (key) {
            var value = data[key];
            formData.append(key, value);
        });
        // console.log("request post",{url:url,post:data});

        let fetchOptions = {
            method: 'POST',
            headers: {
                'Accept': 'application/json',
                'Content-Type': 'multipart/form-data',// 'Content-Type': 'application/json'
            },
            body: formData
        };

        let tmpUrl = url;
        for (var xx in formData) {
            if (formData[xx] != undefined && formData[xx] != '')
                tmpUrl += '/' + xx + '/' + formData[xx];
        }
        console.log('tmpUrl:' + tmpUrl);
        let debug = '';
        let dd = true;
        fetch(url, fetchOptions)
            .then((response) => response.text())
            .then((responseText) => {
                if (dd) debug = responseText;
                // console.log("responseText",responseText);
                let result = JSON.parse(responseText);
                successCallback(result);
                //successCallback(result.status, result.code, result.message, result.data, result.share);
            })
            .catch((err) => {
                //Toast.message('网络异常');
                //ModalIndicator.hide();
                //if (dd) console.log("post_debug:", debug);
                // console.log('failCallback',failCallback);
                console.log('failCallback-err', err);
                //failCallback("post errorB:[" + url + "][" + err + "]");
            });
    }

}
export default util;
